/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: GaoBo
 * Date: 2021-04-10
 * Time: 10:46
 */
class Student {

    //public  公开的  公有的
    private String name;
    private int age = 9;
    private String sex;

    public static int count = 8;

    static {
        count = 8888;
        System.out.println("静态代码块！他只会执行1次！");
    }

    {
        //一般初始化实例数据成员
        this.age = 99;
        System.out.println("实例代码块！构造代码块！执行了！");
    }

    public Student() {
        //this("caocao");//必须放在第一行
        //this("zhangsna",18,"fadfsasadfa"); 只能调用一个
        System.out.println("不带参数的构造方法执行了！");
    }

    public Student(String name) {
        this.name = name;
        System.out.println("带有1个参数的构造方法执行了！");
    }

    public Student(String name, int age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
        System.out.println("调用了带有3个参数的构造方法！");
    }




    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public void eat() {
        System.out.println(Student.count);
        System.out.println(this.name+" eat()!");
    }

    public void sleep() {
        System.out.println(this.name+"sleep()!");
    }

    //静态方法内部 不能用this
    public static void staticFunc() {
        //System.out.println(this.age);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex='" + sex + '\'' +
                '}';
    }
}
public class TestDemo2 {

    public static void func2(Student student) {
        student.eat();
    }

    public static void main(String[] args) {

        func2(new Student());

        //如果只是用1次这个对象 那么建议你使用匿名对象
        new Student().eat();
        new Student().eat();
        new Student().eat();

        Student stu = new Student();
        stu.eat();
        stu.eat();
        stu.eat();
        func2(stu);
    }


    public static void main13(String[] args) {
        Student stu = new Student();
        System.out.println(stu.getAge());//
        System.out.println(Student.count);//
        /*System.out.println("====================");

        Student stu2 = new Student();
*/
    }

    public static void main2(String[] args) {

        Student stu = new Student("caocao");
        System.out.println("===================");
        Student stu2 = new Student();

    }


    public static void main1(String[] args) {

        Student stu = new Student();
        stu.setName("caocao");
        System.out.println(stu.getName());

        stu.setAge(10);
        System.out.println(stu.getAge());


   /*     Student stu = new Student();
        stu.name = "xiaoming";
        stu.age = 18;
        stu.sex = "男";
        System.out.println(stu);*/

    }
}
